<?php

namespace App\Console\Commands;

use App\Models\System\User;
use Illuminate\Console\Command;

class CopyTeacherInfo extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'CopyTeacherInfo {user_id?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '同步copy教师信息';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $userId = $this->argument('user_id');

        $this->info("---开始copy数据,开始:".date('H:i:s')."---");
        $this->runProgram($userId);
        // Log::channel('daily')->info('准备推送学生作业&体育锻炼数据到DEC');
        $this->info("---copy结束,结束:".date('H:i:s')."---");
    }

    private function runProgram($userId = '')
    {
        if($userId) {
            $user = User::where('username', $userId)->with('group')->first();
            if($user) {
                $this->copyHandle($user);
            }
        } else {
            $users = User::where('group_id', '>', 0)->where('deleted', 0)->with('group')->get();
            
            $users->chunk(2)->map(function ($user, $key) {
                dd($user->toArray());
                $this->copyHandle($user);
            });
        }
    }

    private function copyHandle($user)
    {
        dd($user);
    }
}
